home *** CD-ROM | disk | FTP | other *** search
/ PC Plus SuperCD (UK) 1998 May / PCPlus May 1998=disk A.iso / full / CBUILDER / SAMS / SAMPLES / CHAP02 / MAILLIST.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1997-02-12  |  2.1 KB  |  95 lines

  1. #include <iostream.h>
  2. #include <conio.h>
  3. #include <stdlib.h>
  4. #pragma hdrstop
  5.  
  6. #include "structur.h"
  7.  
  8. void displayRecord(int, mailingListRecord mlRec);
  9.  
  10. int main(int, char**)
  11. {
  12.   //
  13.   // create an array of mailingListRecord structures
  14.   //
  15.   mailingListRecord listArray[3];
  16.   cout << endl;
  17.   int index = 0;
  18.   //
  19.   // get three records
  20.   //
  21.   do {
  22.     cout << "First Name: ";
  23.     cin.getline(listArray[index].firstName,
  24.       sizeof(listArray[index].firstName) - 1);
  25.     cout << "Last Name: ";
  26.     cin.getline(listArray[index].lastName,
  27.       sizeof(listArray[index].lastName) - 1);
  28.     cout << "Address: ";
  29.     cin.getline(listArray[index].address,
  30.       sizeof(listArray[index].address) - 1);
  31.     cout << "City: ";
  32.     cin.getline(listArray[index].city,
  33.       sizeof(listArray[index].city) - 1);
  34.     cout << "State: ";
  35.     cin.getline(listArray[index].state,
  36.       sizeof(listArray[index].state) - 1);
  37.     char buff[10];
  38.     cout << "Zip: ";
  39.     cin.getline(buff, sizeof(buff) - 1);
  40.     listArray[index].zip = atoi(buff);
  41.     index++;
  42.     cout << endl;
  43.   }
  44.   while (index < 3);
  45.   //
  46.   // clear the screen
  47.   //
  48.   clrscr();
  49.   //
  50.   // display the three records
  51.   //
  52.   for (int i=0;i<3;i++) {
  53.     displayRecord(i, listArray[i]);
  54.   }
  55.   //
  56.   // ask the user to choose a record
  57.   //
  58.   cout << "Choose a record: ";
  59.   char rec;
  60.   //
  61.   // be sure only 1, 2, or 3 was selected
  62.   //
  63.   do {
  64.     rec = getch();
  65.     rec -= 49;
  66.   } while (rec < 0 || rec > 2);
  67.   //
  68.   // assign the selected record to a temporary variable
  69.   //
  70.   mailingListRecord temp = listArray[rec];
  71.   clrscr();
  72.   cout << endl;
  73.   //
  74.   // display the selected recrord
  75.   //
  76.   displayRecord(rec, temp);
  77.   getch();
  78.   return 0;
  79. }
  80.  
  81. void displayRecord(int num, mailingListRecord mlRec)
  82. {
  83.   cout << "Record " << num + 1 << ":" << endl;
  84.   cout << "Name:     " << mlRec.firstName << " ";
  85.   cout << mlRec.lastName;
  86.   cout << endl;
  87.   cout << "Address:  " << mlRec.address;
  88.   cout << endl << "          ";
  89.   cout << mlRec.city << ", ";
  90.   cout << mlRec.state << "  ";
  91.   cout << mlRec.zip;
  92.   cout << endl << endl;
  93. }
  94.  
  95.